package com.ruoyi.application.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Repository;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.application.domain.Application;
import com.ruoyi.application.service.IApplicationService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 用车申请Controller
 * 
 * @author ruoyi
 * @date 2025-07-08
 */
@RestController
@RequestMapping("/v3/application")
public class ApplicationController extends BaseController
{
    @Autowired
    private IApplicationService applicationService;

    /**
     * 查询用车申请列表
     */
    @PreAuthorize("@ss.hasPermi('v3:application:list')")
    @GetMapping("/list")
    public TableDataInfo list(Application application)
    {
        startPage();
        List<Application> list = applicationService.selectApplicationList(application);
        return getDataTable(list);
    }

    /**
     * 导出用车申请列表
     */
    @PreAuthorize("@ss.hasPermi('v3:application:export')")
    @Log(title = "用车申请", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Application application)
    {
        List<Application> list = applicationService.selectApplicationList(application);
        for (Application a : list) {
            System.out.println( a.getClass());
        }
        ExcelUtil<Application> util = new ExcelUtil<Application>(Application.class);
        util.exportExcel(response, list, "用车申请数据");
    }

    /**
     * 获取用车申请详细信息
     */
    @PreAuthorize("@ss.hasPermi('v3:application:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(applicationService.selectApplicationById(id));
    }

    /**
     * 新增用车申请
     */
    @PreAuthorize("@ss.hasPermi('v3:application:add')")
    @Log(title = "用车申请", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Application application)
    {
        return toAjax(applicationService.insertApplication(application));
    }

    /**
     * 修改用车申请
     */
    @PreAuthorize("@ss.hasPermi('v3:application:edit')")
    @Log(title = "用车申请", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Application application)
    {
        return toAjax(applicationService.updateApplication(application));
    }

    /**
     * 删除用车申请
     */
    @PreAuthorize("@ss.hasPermi('v3:application:remove')")
    @Log(title = "用车申请", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(applicationService.deleteApplicationByIds(ids));
    }
    /**
     * 撤销
     */
    @PreAuthorize("@ss.hasPermi('v3:application:updatateStatus')")
    @Log(title = "撤销", businessType = BusinessType.UPDATE)
    @PostMapping("revoke/{id}")
    public void updatateStatus (@PathVariable Long id)
    {
        applicationService.updateStatus(id);
    }
}
